package com.yoso.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author shizejin
 * @date 2021/12/31
 * @description:
 */
public class MyThreadPool {
    private static ExecutorService executorService = null;
    public static ExecutorService getInstance(){
        if (executorService == null) {
            synchronized (MyThreadPool.class) {
                if (executorService == null) {
                    executorService = new ThreadPoolExecutor(
                            5,
                            10,
                            9000,
                            TimeUnit.MILLISECONDS,
                            new LinkedBlockingQueue<Runnable>(),
                            new MyThreadFactory("YosoThreadPool-Execute"));
                }
            }
        }
        return executorService;
    }
}
